package com.idealighter.game.games.orderma.struct;

import com.idealighter.game.core.common.Game;
import com.idealighter.game.dictionary.domain.OrdermaRoomDomain;
import com.idealighter.game.games.common.AbstractRoom;
import com.idealighter.game.games.common.AbstractTable;
import com.idealighter.game.games.orderma.manager.OderMaDataMgr;
import com.idealighter.game.server.context.ApplicationContext;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 血战到底房间 .
 * 
 * @date 2016年9月2日 上午10:48:35
 *
 */
public class OderMaRoom extends AbstractRoom {

  public final Map<Integer, OderMaTable> tables;

  public OderMaRoom(OrdermaRoomDomain roomDom) {
    super(roomDom.getId(), roomDom.getName());
    this.tables = createTables(roomDom.getTable());
  }

  /**
   * 创建桌子 .
   * 
   * @param tableNum .
   * @return
   */
  private Map<Integer, OderMaTable> createTables(int tableNum) {
    Map<Integer, OderMaTable> tables = new LinkedHashMap<>();

    for (int i = 0; i < tableNum; i++) {
      int tableId = id.intValue() * AbstractTable.MAX_TABLE + i + 1;
      tables.put(tableId, new OderMaTable(tableId, this));
    }

    return tables;
  }

  @Override
  public Game game() {
    return Game.ODERMA;
  }

  @Override
  public OderMaSeat seat(long playerId) {
    return ApplicationContext.getBean(OderMaDataMgr.class).getPlayerSeat(playerId);
  }

  @Override
  public Collection<OderMaTable> tables() {
    return tables.values();
  }

}
